package com.mezz.bones.im.logic.strategy.impl;

import com.alibaba.fastjson.JSON;
import com.mezz.bones.im.logic.notify.domain.request.PrivateMessageBeforeSendRequest;
import com.mezz.bones.im.logic.notify.domain.response.PrivateMessageBeforeSendResponse;
import com.mezz.bones.im.logic.strategy.IImCallbackStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class BeforeMessageCreateStrategy implements IImCallbackStrategy {
    
    @Override
    public String tag() {
        return PRIVATE_MESSAGE_BEFORE_SEND;
    }

    @Override
    public Object process(String body) {


        log.info("消息发送前回调, body: {}", body);
        PrivateMessageBeforeSendRequest request = JSON.parseObject(body, PrivateMessageBeforeSendRequest.class);


        //加锁放重试机制触发伪并发

        //用户-用户
        //用户-供应商
        //用户-平台

        // 处理具体业务逻辑
        // 文本内容 敏感消息、违禁消息、客服消息会话延时断开启动(用户N分钟内没有回复客服则视为自动结束会话)

        // 用户被禁言 返回对应code 且 sync2Peer=0 msgBlocked=1

        PrivateMessageBeforeSendResponse response = new PrivateMessageBeforeSendResponse();
        response.setContent(request.getContent());
        response.setMsgExtra(request.getMsgExtra());
        response.setSync2Peer(request.getSync2Peer());
        return response;
    }
}